package com.nisco.dms.util.auto;

import java.util.ArrayList;
import java.util.List;

import com.nisco.dms.entity.SqlColumn;
import com.nisco.dms.entity.SqlTable;

/**
 * Dao文件自动生成
 * 
 * @author Robin. 2013-1-24
 * 
 */
public class DaoAuto {

	private String className;
	private SqlTable sqlTable;

	public DaoAuto(SqlTable sqlTable, List<SqlColumn> columns) {
		this.sqlTable = sqlTable;
	}

	/**
	 * 生成dao文件
	 */
	public void createDao() {
		List<String> list = new ArrayList<String>();
		// 获取模板
		TextFile textFile = new TextFile(
				"src/main/resources/codeTemplate/DaoTemplate.txt");
		// 根据表名生成实体类名，根据'_'分割，并将分割后的字符串首字母大写
		// if (sqlTable.getTabName().toString().contains("_")) {
		// String[] classNames = sqlTable.getTabName().split("_");
		// for (int i = 1; i < classNames.length; i++) {
		// className += WordUtil.firstUpper(classNames[i].toString());
		// }
		// } else {
		// className = WordUtil.firstUpper(sqlTable.getTabName());
		// }
		className = WordUtil.firstUpper(WordUtil.spliteWord("_",
				sqlTable.getTabName()));
		list.add("[dao_name]" + "<==>" + className + "Dao");
		list.add("[entity_name]" + "<==>" + className);
		textFile.write("src/main/resources/autocode/" + className + "Dao.java",
				list);
	}
}
